/**
 * Created by lighter on 2014/12/9.
 */
package Hxw3DEngine.asset.parsers.bson {
import flash.utils.ByteArray;

public class Header {

    private var _magic:String;
    private var _major:uint;
    private var _minor:uint;
    private var _length:uint;	// 未压缩长度
    private var _flags:uint;

    public static const length:uint = 16;
    public static const compressionMask:uint = 0x3;

    public function Header(ba:ByteArray) {
        _magic = ba.readUTFBytes(4);
        _major = ba.readUnsignedShort();
        _minor = ba.readUnsignedShort();
        _length = ba.readUnsignedInt();
        _flags = ba.readUnsignedInt();
    }
    public function IsValid(magic:String,major:uint,minor:uint):Boolean{
        return (_magic == magic) && ((_major > major) || ((_major == major) && (_minor >= minor)));
    }

    public function get flags():uint {
        return _flags;
    }

    public function get compressionMethod():uint{
        return compressionMask & _flags;
    }
}
}
